package com.tjise.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tjise.commonutils.R;
import com.tjise.eduservice.entity.EduCourse;
import com.tjise.eduservice.entity.EduTeacher;
import com.tjise.eduservice.service.EduCourseService;
import com.tjise.eduservice.service.EduTeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/eduservice/indexfront")

@Api(description = "首页数据显示")
public class IndexFrontController {

    @Autowired
    private EduCourseService courseService;

    @Autowired
    private EduTeacherService teacherService;

    //查询前8条热门课程 查询前4条名师
    @ApiOperation("查询前8条热门课程 查询前4条名师")
    @GetMapping("index")
    public R index(){
        QueryWrapper<EduCourse> Wrapper = new QueryWrapper<>();
        Wrapper.eq("status","Normal");
        Wrapper.orderByDesc("id");
        Wrapper.last("limit 8");
        List<EduCourse> eduList = courseService.list(Wrapper);

        QueryWrapper<EduTeacher> WrapperTeacher = new QueryWrapper<>();
        WrapperTeacher.orderByDesc("sort");
        WrapperTeacher.last("limit 4");
        List<EduTeacher> teacherList = teacherService.list(WrapperTeacher);

        return R.ok().data("eduList",eduList).data("teacherList",teacherList);
    }
}
